package com.rabbit2020.web;

import com.rabbitmq.client.AMQP;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 作者: LCG
 * 日期: 2020/2/27 22:27
 * 描述:
 */
@RestController
public class TestRabbitMq {


    @Autowired
     private RabbitTemplate rabbitTemplate;

     //@Autowired
     //private RabbitTemplateConfig rabbitTemplateConfig;//发送确认 回调

    /**
     * 死信队列测试
     * @return
     */
    @RequestMapping("sixin")
    public String testSixin(){

        String format = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        rabbitTemplate.convertAndSend("PU-TONG-EXCHANGE", "PU-TONG-KEY", "=死信测试-"+format,new MyMessagePost());


        return "OK";
    }


    @RequestMapping("sixin2")
    public String testSixin2(){

        AMQP.BasicProperties build = new AMQP.BasicProperties().builder().expiration("10000").build();

        String format = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");

        rabbitTemplate.convertAndSend("PU-TONG-EXCHANGE", "PU-TONG-KEY", "2死信测试-"+format,new MyMessagePost());

        return "OK";
    }

}
